package com.example.elasticsearch.controller;

import com.common.utils.R;
import com.es.vo.SkuESModel;
import com.example.elasticsearch.service.ElasticSearchSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author guanglin.ma
 * @date 2023-12-17 22:31
 */
@RequestMapping("/search/save")
@RestController
public class ElasticSearchSaveController {

    @Autowired
    private ElasticSearchSaveService service;

    /**
     * 存储商品上架信息到ElasticSearch服务的接口
     * @return
     */
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuESModel> skuESModels){
        Boolean b = false;
        try {
            b = service.productStatusUp(skuESModels);
        } catch (IOException e) {
            // e.printStackTrace();
            return R.error(1003, "es上架错误");
        }
        if(b){
            return R.ok();
        }
        return R.error(1003, "es上架错误");
    }
}
